import UIKit

extension UIView {
    //============== Click ==============
    struct AssociatedClosureClass_Click {
        var eventClosure_Click: (UITapGestureRecognizer)->()
    }
    
    private struct AssociatedKeys {
        static var eventClosureObj_Click:AssociatedClosureClass_Click?
    }
    
    private var eventClosureObj_Click: AssociatedClosureClass_Click{
        set{
            objc_setAssociatedObject(self, &AssociatedKeys.eventClosureObj_Click, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
        }
        get{
            return (objc_getAssociatedObject(self, &AssociatedKeys.eventClosureObj_Click) as? AssociatedClosureClass_Click)!
        }
    }
    
    open func addYTapGestureRecognizer(_ action:@escaping (UITapGestureRecognizer)->()) {
        let eventObj = AssociatedClosureClass_Click(eventClosure_Click: action)
        eventClosureObj_Click = eventObj
        addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(eventExcuate_Click(sender:))))
    }
    
    @objc private func eventExcuate_Click(sender: UITapGestureRecognizer){
        eventClosureObj_Click.eventClosure_Click(sender)
    }
    
    //============== longClick ==============
    struct AssociatedClosureClass_LongClick {
        var eventClosure_LongClick: (UILongPressGestureRecognizer)->()
    }
    
    private struct AssociatedKeys_LongClick {
        static var eventClosureObj_LongClick:AssociatedClosureClass_LongClick?
    }
    
    private var eventClosureObj_LongClick: AssociatedClosureClass_LongClick{
        set{
            objc_setAssociatedObject(self, &AssociatedKeys_LongClick.eventClosureObj_LongClick, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
        }
        get{
            return (objc_getAssociatedObject(self, &AssociatedKeys_LongClick.eventClosureObj_LongClick) as? AssociatedClosureClass_LongClick)!
        }
    }
    
    open func addYLongGestureRecognizer(_ action:@escaping (UILongPressGestureRecognizer)->()) {
        let eventObj = AssociatedClosureClass_LongClick(eventClosure_LongClick: action)
        eventClosureObj_LongClick = eventObj
        addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(eventExcuate_LongClick(sender:))))
    }
    
    @objc private func eventExcuate_LongClick(sender: UILongPressGestureRecognizer){
        eventClosureObj_LongClick.eventClosure_LongClick(sender)
    }
}
